package com.zebra.common;

import io.netty.buffer.ByteBuf;
import lombok.*;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ZbmMessage extends ZebraBaseMessage<ZbmMessage> {

    private int zbmType; //消息 类型 1，系统级， 2 中间广播 3，个人通知
    private int zbmArea; // ZbmAreaType
    private int[] gameIds;
    private long[] userIds;
    private String msgJson; //消息体； json

    @Override
    public void write(ByteBuf b) {
        b.writeInt(this.zbmType);
        b.writeInt(this.zbmArea);
        ByteBufUtils.writeIntArray(b, this.gameIds);
        ByteBufUtils.writeLongArray(b, this.userIds);
        ByteBufUtils.writeString(b, this.msgJson);
    }

    @Override
    public ZbmMessage read(ByteBuf b) {
        this.zbmType = readInt(b);
        this.zbmArea = readInt(b);
        this.gameIds = ByteBufUtils.readIntArray(b);
        this.userIds = ByteBufUtils.readLongArray(b);
        this.msgJson = ByteBufUtils.readString(b);
        b.release();
        return this;
    }

    //发送给玩家 不需要 不必要信息
    public void writeByPlayer(ByteBuf b){
        b.writeInt(this.zbmType);
        ByteBufUtils.writeString(b, this.msgJson);
    }
}
